package com.haixiaoke.saas.enterprise.bill.controller;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.annotation.TenantScope;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.tenant.TenantContext;
import com.haixiaoke.saas.house.domain.House;
import com.haixiaoke.saas.house.service.IHouseService;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.system.domain.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 账单分账Controller
 *
 * @author xiaolong
 * @date 2024-06-11
 */
@RestController
@RequestMapping("/enterprise/bill/allocation")
public class EnterpriseRevenueAllocationController extends BaseController {

    @Autowired
    private IHouseService houseService;

    /**
     * 查询账单分账列表
     */
    @PreAuthorize("@ss.hasPermi('bill:allocation:list')")
    @GetMapping("/list")
    @TenantScope
    public TableDataInfo list(House house) {
        startPage();
        house.setTenantId(TenantContext.getTenantId());
        List<House> list = houseService.selectHouseList(house);
        return getDataTable(list);
    }


    /**
     * 编辑分账信息
     */
    @PreAuthorize("@ss.hasPermi('bill:allocation:edit')")
    @PutMapping
    @TenantScope
    @RepeatSubmit
    public AjaxResult editAllocation(@RequestBody House house) {
        Long userId = getUserId();
        house.setUpdateBy(String.valueOf(userId));
        LoginUser loginUser = getLoginUser();
        house.setBizUserBusiness(loginUser.getBizUser());
        return toAjax(houseService.editAllocation(house));
    }
}
